#include "SDLResources.h"

SDLResources* SDLResources::instance = 0;

SDLResources::SDLResources()
{
	mLoadedTextures = std::map<std::string, SDL_Surface*>();
	mLoadedFonts = std::map<std::string, TTF_Font*>();
}

SDLResources::~SDLResources()
{
}

SDL_Surface* SDLResources::GetTexture(std::string fileName)
{
	if(mLoadedTextures[fileName] == 0)
	{
		LoadImage(fileName);
	}
	return mLoadedTextures[fileName];
}

TTF_Font* SDLResources::GetFont(std::string fileName, int size)
{
	std::stringstream ss;
	ss << fileName << size;
	if(mLoadedFonts[ss.str()] == 0)
	{
		LoadFont(fileName, size);
	}
	return mLoadedFonts[ss.str()];
}

void SDLResources::LoadFont( std::string fileName, int size)
{
	std::stringstream ss;
	std::stringstream newFileName;

	ss << fileName << size;
	newFileName << "Fonts/" << fileName;

	TTF_Font* loadedFont = TTF_OpenFont(newFileName.str().c_str(), size);
	
	mLoadedFonts[ss.str()] = loadedFont;
}

void SDLResources::LoadImage( std::string fileName)
{
	SDL_Surface* loadedImage = 0;

	loadedImage = IMG_Load(fileName.c_str());

	mLoadedTextures[fileName] = loadedImage;
}